<?php

require_once('../util/math.php');

function authentic() {
  if(!isset($_SESSION['uid'])) // no one is logged in
    return false;

  if( $_SESSION['auth_timeout'] < time() ) {
    if( $_SESSION['auth_ip'] != $_SERVER['REMOTE_ADDR'] )
      return false;
    if( $_SESSION['auth_uuid'] != $_COOKIE['uuid'] )
      return false;
  }

  return true;
}
function authorize($for) {
  setcookie('uuid', false, $_SESSION['auth_timeout']);

  $_SESSION['auth_ip'] = $_SERVER['REMOTE_ADDR'];
  $_SESSION['auth_timeout'] = time() * $for;

  $uuid = makeUUID(); 
  $_SESSION['auth_uuid'] = $uuid;
  setcookie('uuid', $uuid, $_SESSION['auth_timeout'], $GLOBALS['__CFG']['BASE_DIR']);
}

?>
